package com.souku.finance.application.ui.mine;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.manager.RequestManager;
import com.souku.finance.application.R;
import com.souku.finance.application.base.BaseTitleBarActivity;
import com.souku.finance.application.bean.CurrentBean;
import com.souku.finance.application.http.UrlConstact;
import com.souku.finance.application.http.volley.ReqListener;
import com.souku.finance.application.http.volley.Success;
import com.souku.finance.application.ui.invite.ShouKuTenderDetailsActivity;
import com.souku.finance.application.ui.invite.TenderDetailsActivity;
import com.souku.finance.application.utils.Constant;
import com.souku.finance.application.utils.JsonUtil;
import com.souku.finance.application.utils.MyTextUtil;
import com.souku.finance.application.utils.ParamUtil;
import com.souku.finance.application.utils.ToastUtil;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 首库宝
 */
public class ShouKuDetailsActivity extends BaseTitleBarActivity {

    @BindView(R.id.imageView2)
    ImageView imageView2;
    @BindView(R.id.ll_zhuanru)
    LinearLayout llZhuanru;
    @BindView(R.id.ll_zhuanchu)
    LinearLayout llZhuanchu;
    @BindView(R.id.tv_current_rate)
    TextView tvCurrentRate;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.tv_cumulated_interest)
    TextView tvCumulatedInterest;
    @BindView(R.id.tv_available_interest)
    TextView tvAvailableInterest;
    @BindView(R.id.tv_yesterday_money)
    TextView tvYesterdayMoney;
    @BindView(R.id.rl_currentmoneylist)
    RelativeLayout rlCurrentmoneylist;
    @BindView(R.id.rl_currentrecordlist)
    RelativeLayout rlCurrentrecordlist;

    private CurrentBean bean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shou_ku_details);
        ButterKnife.bind(this);
    }

    @Override
    public void internet() {

    }

    @OnClick({R.id.ll_zhuanru, R.id.ll_zhuanchu, R.id.rl_currentmoneylist, R.id.rl_currentrecordlist})
    public void onViewClicked(View view) {
        Intent intent = new Intent();
        switch (view.getId()) {
            case R.id.ll_zhuanru://转入
                intent.setClass(this, ShouKuTenderDetailsActivity.class);
                intent.putExtra(Constant.Default, "1");
                startActivity(intent);
                break;
            case R.id.ll_zhuanchu://转出
                if (bean == null) {
                    queryUserDealInfo();
                    return;
                }
                intent.setClass(this, CurrentOutActivity.class);
                intent.putExtra(Constant.Default, bean);
                startActivity(intent);
                break;
            case R.id.rl_currentmoneylist://在投本金
                intent.setClass(this, CurrentMoneyActivity.class);
                intent.putExtra(Constant.Default, "1");
                startActivity(intent);
                break;
            case R.id.rl_currentrecordlist://累计收益
                if (bean == null) {
                    queryUserDealInfo();
                    return;
                }
                intent.setClass(this, CurrentDetailedActivity.class);
                intent.putExtra(Constant.Default, bean);
                startActivity(intent);
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        queryUserDealInfo();
    }

    //获取活期详情
    private void queryUserDealInfo() {
        HashMap<String, String> map = ParamUtil.getParams();
        RequestManager.getInstance().post(UrlConstact.QUERY_USER_DEAL_INFO, ParamUtil.getSing(map), new ReqListener(this, new Success() {
            @Override
            public void onSuccess(String response) {
                if (JsonUtil.getCode(response) == 1) {
                    bean = JsonUtil.fastBean(JsonUtil.getData(response).toString(), CurrentBean.class);
                    setData(bean);
                } else {
                    ToastUtil.show(JsonUtil.getMessage(response));
                }
            }
        }), ParamUtil.getHeaders());
    }

    private void setData(CurrentBean bean) {
        tvYesterdayMoney.setText("昨天收益(元)：" + MyTextUtil.setMoneyToElement(bean.getYesInterest())); //昨天收益
        tvCurrentRate.setText(bean.getCurrentDealLoadDO().getCurrentRate());//年化率
        tvMoney.setText(MyTextUtil.setMoneyToElement(bean.getCurrentDealLoadDO().getMoney()));//再投本金
        tvCumulatedInterest.setText(MyTextUtil.setMoneyToElement(bean.getCurrentDealLoadDO().getCumulatedInterest()));//累计收益
        tvAvailableInterest.setText(MyTextUtil.setMoneyToElement(bean.getCurrentDealLoadDO().getAvailableInterest()));//可提取收益(元)
    }

}
